<template>
	<view class="content">
		<view class="card">
			<step value="2"></step>
		</view>
		<view class="card">
			<cell title='法定代表人姓名' v-model="formData.name" maxlength="11" required></cell>
			<cell title='法定代表人与实际控制人是否一致' mode="radios" v-model="formData.check"
				:radios="[{label: '是', value: '1'}, {label: '否', value: '2'}]" required></cell>
			<cell title='企业实际控制人姓名' v-model="formData.sjname" required></cell>
			<cell title='企业实际控制人身份证号' v-model="formData.sjcard" required></cell>
			<cell title='申请分行' v-model="formData.sqfh" required></cell>
			<cell title='办理支行' v-model="formData.blzh" required></cell>
		</view>
		<button class="btn" size="default" type="primary" @click="jump()" hover-class="is-hover">下一步</button>
	</view>
</template>

<script>
	import step from "@/components/step.vue"
	export default {
		components: {
			step
		},
		data() {
			return {
				formData: {
					name: '张三',
					check: '1',
					sjname: '张三',
					sjcard: '511018****',
					sqfh: '四川省分行',
					blzh: '成都支行',
				}
			}
		},
		mounted() {
			try{
				this.formData = JSON.parse(uni.getStorageSync('isInsertInfo'))
			}catch(e){
				//TODO handle the exception
				this.formData ={
					name: '张三',
					check: '1',
					sjname: '张三',
					sjcard: '511018****',
					sqfh: '四川省分行',
					blzh: '成都支行',
				}
			}
		},
		methods: {
			toast(title) {
				uni.showToast({
					icon: "none",
					title,
				})
			},
			async jump() {
				if (!this.formData.name) {
					this.toast('请填写法定代表人姓名')
					return
				}
				
				if (!this.formData.sjname) {
					this.toast('请填写企业实际控制人姓名')
					return
				}
				if (!this.formData.sjcard) {
					this.toast('请填写企业实际控制人身份证号')
					return
				}
				if (!this.formData.sqfh) {
					this.toast('请填写申请分行')
					return
				}
				if (!this.formData.blzh) {
					this.toast('请填写办理支行')
					return
				}
				await this.$myloading() // async
				uni.setStorageSync('infoInput', JSON.stringify(this.formData));
				uni.navigateBack({
					delta: this.go * 1
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.btn {
		margin-top: 60rpx;
		width: calc(100% - 60rpx);
	}
</style>